package com.ruoyi.web.controller.docs;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.docs.domain.dto.ArticleTreeDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.docs.domain.BizActivity;
import com.ruoyi.docs.service.IBizActivityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动列表Controller
 * 
 * @author ruoyi
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/docs/activity")
public class BizActivityController extends BaseController
{
    @Autowired
    private IBizActivityService bizActivityService;

    /**
     * 查询活动列表列表
     */
    @PreAuthorize("@ss.hasPermi('docs:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizActivity bizActivity)
    {
        startPage();
        List<BizActivity> list = bizActivityService.selectBizActivityList(bizActivity);
        return getDataTable(list);
    }

    /**
     * 导出活动列表列表
     */
    @PreAuthorize("@ss.hasPermi('docs:activity:export')")
    @Log(title = "活动列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizActivity bizActivity)
    {
        List<BizActivity> list = bizActivityService.selectBizActivityList(bizActivity);
        ExcelUtil<BizActivity> util = new ExcelUtil<BizActivity>(BizActivity.class);
        util.exportExcel(response, list, "活动列表数据");
    }

    /**
     * 获取活动列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('docs:activity:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return success(bizActivityService.selectBizActivityByActivityId(activityId));
    }
    @PreAuthorize("@ss.hasPermi('docs:activity:query')")
    @PostMapping(value = "/createQrcode/{activityId}")
    public void createQrcode(HttpServletResponse response,@PathVariable("activityId") Long activityId)
    {
        bizActivityService.createQrcode(response,activityId);
    }

    /**
     * 新增活动列表
     */
    @PreAuthorize("@ss.hasPermi('docs:activity:add')")
    @Log(title = "活动列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizActivity bizActivity)
    {
        bizActivity.setCreateBy(getUsername());
        return toAjax(bizActivityService.insertBizActivity(bizActivity));
    }

    /**
     * 修改活动列表
     */
    @PreAuthorize("@ss.hasPermi('docs:activity:edit')")
    @Log(title = "活动列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizActivity bizActivity)
    {
        bizActivity.setUpdateBy(getUsername());
        return toAjax(bizActivityService.updateBizActivity(bizActivity));
    }
    @PreAuthorize("@ss.hasPermi('docs:activity:edit')")
    @Log(title = "修改状态", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BizActivity bizActivity)
    {
        bizActivity.setUpdateBy(getUsername());
        return toAjax(bizActivityService.updateBizActivity(bizActivity));
    }
    /**
     * 删除活动列表
     */
    @PreAuthorize("@ss.hasPermi('docs:activity:remove')")
    @Log(title = "活动列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(bizActivityService.deleteBizActivityByActivityIds(activityIds));
    }

    //
    @PreAuthorize("@ss.hasPermi('docs:activity:list')")
    @Log(title = "活动列表", businessType = BusinessType.EXPORT)
    @PostMapping("/getActivityTree")
    public AjaxResult getTree(@RequestBody ArticleTreeDto articleTreeDto)
    {
        return  success(bizActivityService.getTree(articleTreeDto));
    }

}
